//
//  Extension+NSAttributedString.swift
//  YDWeibo01
//
//  Created by suibian on 16/8/21.
//  Copyright © 2016年 iitcast. All rights reserved.
//

import UIKit
extension NSAttributedString{
    
    class func emoticonAttributedString(emoticonModel:YDEmoticonModel,textFont:CGFloat,y:CGFloat)->NSAttributedString {
        //            创建文字附件 (它可以设置image)
        let att = YDTextAttachment()
        //            赋值
        att.emoticonModel = emoticonModel
        //           通过extension获取image
        let image = UIImage.getEmoticonsImage(emoticonModel)
        //            设置image
        att.image = image
        //            计算行高
        let lineHight = UIFont.systemFontOfSize(textFont).lineHeight
        //            一定要设置bounds 设置图片的大小与行高匹配
        att.bounds = CGRect(x: 0, y: y, width: lineHight, height: lineHight)
        //        创建不可变副文本(带有文字附件)
        return NSAttributedString(attachment: att)
    }

}